package com.example.mychatroom.a_utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @className: GetBean
 * @author: 芃
 * @description: 创建Bcrypt对象工具类
 * @date: 2024/3/6 19:40
 */
@Configuration
public class GetBean implements ApplicationContextAware {

    private static ApplicationContext applicationContext;


    @Bean
    public static BCryptPasswordEncoder getBCryptPasswordEncoder(){
        return new BCryptPasswordEncoder();
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }


    public static Object getBean(String beanName){
        return applicationContext.getBean(beanName);
    }
}
